var Adv_skd=require("./Adv_skd")
var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s,
    c = e("ADConfigs"),
    l = e("AssetsMap"),
    d = e("BundleNames"),
    u = e("GlobalParam"),
    p = e("Util"),
    h = e("GameData"),
    f = e("SkinLevelData"),
    _ = cc._decorator,
    y = _.ccclass,
    m =
        (_.property,
        window.wx,
        (function (e) {
            function t() {
                var t = (null !== e && e.apply(this, arguments)) || this;
                return (
                    (t.content = null),
                    (t.rang_length = 0),
                    (t.ItemsParent = null),
                    (t.btn_start = null),
                    (t.isRunAni = !1),
                    (t.btn_start_ad_icon = null),
                    t
                );
            }
            return (
                a(t, e),
                (t.prototype.onResetView = function () {
                    e.prototype.onResetView.call(this),
                        (s = this),
                        0 == u.default.LuckDrawData.length &&
                            (u.default.LuckDrawData = game.BundleManager.instance
                                .getBundle(d.default.Resources)
                                .get(l.default.ResourceBundle.jsons.assetsList.LuckDrawData, cc.JsonAsset).json),
                        this.init();
                }),
                (t.prototype.onDisable = function () {}),
                (t.prototype.onEnable = function () {
                    cc.SDK.showGetUICoinBox(
                        function (e) {
                            var t = h.default.instance.getPlayerCoin();
                            h.default.instance.setPlayerCoin(t + e);
                        },
                        function () {},
                        cc.SDK.gameID
                    );

                    Adv_skd.default.instance.hideAllAdv();

                    Adv_skd.default.instance.showGridAdLeft();
                    Adv_skd.default.instance.showGridAdRight();
                }),
                (t.prototype.onClickClose = function () {
                    
                    Adv_skd.default.instance.hideAllAdv();

                    Adv_skd.default.instance.showGridAdLeftOne();
                    Adv_skd.default.instance.showGridAdRightOne();
                    Adv_skd.default.instance.showInterstitialAd();

                    game.AudioManager.playBtnEffect(), this.closeView(!0);
                }),
                (t.prototype.registerMediator = function () {
                    e.prototype.registerMediator.call(this);
                }),
                (t.prototype.removeMediator = function () {
                    e.prototype.removeMediator.call(this);
                }),
                (t.prototype.addEvent = function () {
                    e.prototype.addEvent.call(this),
                        this.btn_start.on(game.EngineEventType.NodeEvent.click, this.onClickStartRun, this);
                }),
                (t.prototype.removeEvent = function () {
                    e.prototype.removeEvent.call(this),
                        this.turnTableBg.stopAllActions(),
                        this.ItemsParent.stopAllActions(),
                        this.btn_start.off(game.EngineEventType.NodeEvent.click, this.onClickStartRun, this);
                }),
                (t.prototype.onClickStartRun = function () {
                    if (
                        (console.log("ad.adInterface:", ad.adInterface),
                        game.AudioManager.playBtnEffect(),
                        this.btn_start_ad_icon.active)
                    ) {
                        if (ad.curr_platform == window.ad.Platform.WECHAT && "" == c.WeChatParam.rewarded_video_id)
                            return game.UIManager.instance.showToast("广告获取失败，请稍后重试！");
                        ad.adInterface.showRewardedVideo(null, null, function () {
                            s.StartRun();
                        });
                    } else s.StartRun();
                }),
                (t.prototype.StartRun = function () {
                    if (!this.isRunAni) {
                        this.isRunAni = !0;
                        for (
                            var e = p.default.randomFrom(1, this.rang_length),
                                t = this.ItemsParent.children,
                                o = -1,
                                n = 0,
                                i = 0;
                            i < t.length;
                            i++
                        ) {
                            var a = t[i];
                            if (e < a.probability && -1 == o) {
                                (o = i), (n = a.angle);
                                break;
                            }
                        }
                        n = 360 - n;
                        var r = (-this.ItemsParent.angle % 360) + n;
                        r < 0 && (r = 360 + r);
                        var c = cc.rotateBy(0.2, 90),
                            l = cc.repeat(c, 12),
                            d = cc.rotateBy(0.4, 90),
                            u = cc.repeat(d, 4),
                            h = cc
                                .sequence(
                                    l,
                                    u,
                                    cc.rotateBy(0.5, r),
                                    cc.callFunc(function () {
                                        (s.isRunAni = !1), s.act_finish(o);
                                    })
                                )
                                .easing(cc.easeInOut(2));
                        this.ItemsParent.runAction(h);
                    }
                }),
                (t.prototype.init = function () {
                    (this.isCache = !1),
                        (this.content = this.node.getChildByName("content")),
                        (this.ItemsParent = this.content.getChildByName("itemsParent")),
                        (this.btn_start = this.content.getChildByName("btn_start")),
                        (this.btn_start_ad_icon = this.btn_start.getChildByName("ad_icon")),
                        (this.turnTableBg = this.content.getChildByName("turnTable")),
                        this.turnTableBg.runAction(
                            cc.repeatForever(
                                cc.sequence(
                                    cc.delayTime(0.3),
                                    cc.callFunc(function () {
                                        (s.turnTableBg.getChildByName("act1").active =
                                            !s.turnTableBg.getChildByName("act1").active),
                                            (s.turnTableBg.getChildByName("act2").active =
                                                !s.turnTableBg.getChildByName("act1").active);
                                    })
                                )
                            )
                        );
                    for (
                        var e = u.default.LuckDrawData, t = this.ItemsParent.children, o = 0, n = 0;
                        n < t.length;
                        n++
                    ) {
                        var i = t[n];
                        if (
                            (0 == n && (o = 0),
                            (o += e[n].probability),
                            (i.probability = o),
                            (i.children[1].getComponent(cc.Label).string = e[n].chinese + "*" + e[n].num),
                            "fragment" == e[n].type)
                        ) {
                            var a = "fragment_icon_" + e[n].name,
                                r = game.BundleManager.instance
                                    .getBundle(d.default.Popup)
                                    .get(l.default.PopupMap.EggView.preAssets.textures.assetsList[a], cc.SpriteFrame),
                                c = i.getChildByName("item_image").getComponent(cc.Sprite);
                            (c.spriteFrame = r), (c.node.scale = 0.6);
                        }
                    }
                    (this.rang_length = o),
                        (this.btn_start_ad_icon.active =
                            p.default.getItem("LuckDrawTimer", "000") == p.default.getTodayStr());
                }),
                (t.prototype.act_finish = function (e) {
                    var t = u.default.LuckDrawData;
                    if (
                        (game.UIManager.instance.showToast(t[e].chinese + "*" + t[e].num + "已到账"),
                        "fragment" == t[e].type)
                    ) {
                        for (var o = f.SkinLevelData.instance.skinList, n = 0; n < o.length; n++)
                            if (o[n].chinese == t[e].chinese) {
                                f.SkinLevelData.instance.add_fragments(o[n], t[e].num);
                                break;
                            }
                    } else if ("coin" == t[e].type) {
                        var i = u.default.LuckDrawData[e].num,
                            a = h.default.instance.getPlayerCoin();
                        h.default.instance.setPlayerCoin(a + i);
                    }
                    p.default.setItem("LuckDrawTimer", p.default.getTodayStr()), (s.btn_start_ad_icon.active = !0);
                }),
                r([y], t)
            );
        })(game.BasePopView));
i.default = m;
